﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ChessIt
{
    public class Square
    {
        private int row, column;
        private ChessBoard board;
        private int backgroundColor;

        public bool IsEmpty;
        public Image CellImage;
        public Image CellBackground;       

        public Square(int row, int column, ChessBoard board)
        {
            this.row = row;
            this.column = column;
            this.board = board;

            IsEmpty = true;
            CellBackground = new Image();
            CellImage = new Image();
           
            if ((row + column) % 2 == 0)
            {
                CellBackground.Source = Utils.GetImage("white.png");                                         
                //CellImage.Source = Utils.GetImage("white.png");
                backgroundColor = 0;
            }
            else
            {
                CellBackground.Source = Utils.GetImage("black.png");                
                //CellImage.Source = Utils.GetImage("black.png");
                backgroundColor = 1;
            }             
        }

        public void SetIcon(String iconFileName)
        {
            if (iconFileName != null)
            {
                CellImage.Source = Utils.GetImage(iconFileName);
                IsEmpty = false;
            }
            else
            {                
                if (backgroundColor == 0)
                    CellImage.Source = Utils.GetImage("white.png");
                else
                    CellImage.Source = Utils.GetImage("black.png");
                
                //CellImage.Source = null;
                IsEmpty = true;
            }
        }

        public void setSelect(bool select)
        {
            if (select)
            {
                if (backgroundColor == 0)
                    CellBackground.Source = Utils.GetImage("white_h.png");
                else
                    CellBackground.Source = Utils.GetImage("black_h.png");
            }
            else
            {
                if (backgroundColor == 0)
                    CellBackground.Source = Utils.GetImage("white.png");
                else
                    CellBackground.Source = Utils.GetImage("black.png");
            }
        }
    }
}
